package com.dys.servlet;

import com.dys.entity.Emp;
import com.dys.service.EmpService;
import com.dys.service.impl.EmpServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Author: 疾风
 * @ClassName: EmpServlet
 * @Description: Emp控制器
 * @CreateDate: 2024/09/24
 * @Version: v1.0.0
 */
@WebServlet(urlPatterns = "/empServlet.do")
public class EmpServlet extends HttpServlet {
    EmpService empService = new EmpServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取数据
        List<Emp> emps = empService.findAll();
        emps.stream().forEach(System.out::println);
        // 将数据放入请求域中
        req.setAttribute("emps", emps);
        // 请求转发给jsp
        req.getRequestDispatcher("showEmp.jsp").forward(req, resp);
    }
}
